package com.btobtob.a.biz.user.commonweb.local;

import jakarta.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.support.RequestContextUtils;

import java.util.Locale;

/**
 * @author: Arthur
 * @date: 2021/12/14 17:53
 */
public class LocalUtil {
    private final Logger logger = LoggerFactory.getLogger(LocalUtil.class);


    public static String getLocalLanguage() {
        Locale locale;
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            locale = RequestContextUtils.getLocale(request);
        } catch (Exception var3) {
            locale = Locale.ENGLISH;
        }

        return locale.getLanguage();
    }

    public static Locale getLocal() {
        Locale locale;
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            locale = RequestContextUtils.getLocale(request);
        } catch (Exception var3) {
            locale = Locale.SIMPLIFIED_CHINESE;
        }

        return locale;
    }


}
